// 生成 avue-crud 配置项
export const crudOptionHelper = ({ ...option }) => {
  return {
    height: 'calc(100vh - 440px)', // 表格的高度，默认为自动高度
    calcHeight: 30, //
    tip: false, // ?内容提示辅助语
    searchShow: true, // 表格搜索首次是否展示
    searchMenuSpan: 6, // ?
    labelWidth: 130, // ?标题宽度
    border: true, // 是否带有纵向边框

    // 是否有序号
    index: true,
    indexLabel: '序号',

    // 表格查看按钮
    viewBtn: true,
    viewBtnText: '详情',
    viewTitle: '详情',

    selection: true, // 是否有选择框
    dialogClickModal: false, // 表格弹窗是否可以通过点击modal关闭

    columnBtn: false, // 表格列操作按钮-avue-curd控制列显隐的按钮，已被自定义的user-table-config替换
    ...option
  };
};
export const crudInModalOptionHelper = ({ ...option }) => {
  return {
    height: '300',
    calcHeight: 30,
    tip: false,
    border: true,
    index: true,
    indexLabel: '序号',
    selection: false,
    addBtn: true,

    delBtn: true,
    viewBtn: true,
    viewBtnText: '详情',
    editBtn: false,
    menu: true,
    refreshBtn: false,
    columnBtn: false,
    ...option
  };
};

// 生成表单配置项
export const columnOptionHelper = ({ label, prop, ...option }) => {
  return {
    label,
    prop,
    addDisplay: false,
    editDisplay: false,
    viewDisplay: false,
    ...option
  };
};
export const selectOptionHepler = ({ label, prop, search = true, required = true, rules = [], ...option }) => {
  rules = required
    ? [
        {
          required,
          message: `请输入${label}`,
          trigger: 'blur'
        },
        ...rules
      ]
    : [];

  return {
    label,
    prop,
    search,
    type: 'select',
    rules: rules,
    // 数据来源于数据字典
    props: {
      label: 'dictValue',
      value: 'dictKey'
    },
    // multiple: false,
    // hide: true,
    // viewDisplay: false,
    // props: {
    //   label: 'title',
    //   value: 'id'
    // },
    // nodeClick: (data, node, nodeComp) => {
    //   this.form.deptName = data.title;
    // },
    ...option
  };
};
export const inputOptionHelper = ({ label, prop, search = true, ...option }) => {
  return {
    label,
    prop,
    search,
    type: 'input',
    rules: [
      {
        required: true,
        message: `请输入${label}`,
        trigger: 'blur'
      }
    ],
    ...option
  };
};
export const switchOptionHelper = ({ label, prop, ...option }) => {
  return {
    label,
    prop,
    type: 'switch',
    align: 'center',
    ...option
  };
};
export const textareaOptionHelper = ({ label, prop, ...option }) => {
  return {
    label,
    prop,
    type: 'textarea',
    minRows: 3,
    span: 24,
    ...option
  };
};
export const dateOptionHelper = ({ label, prop, ...option }) => {
  return {
    label,
    prop,
    span: 12,
    type: 'date',
    valueFormat: 'yyyy-MM-dd',
    format: 'yyyy-MM-dd',
    ...option
  };
};
export const uploadOptionHelper = ({ label, prop, tip, ...option }) => {
  return {
    label,
    prop,
    tip,
    type: 'upload',
    loadText: '文件上传中，请稍等',
    span: 24,
    propsHttp: {
      res: 'data'
    },
    data: {},
    headers: {
      'Blade-Auth': getToken()
    },
    action: '#',
    ...option
  };
};